package com.itheima.health.controller;


import com.itheima.interfaces.OrderSettingService;
import com.itheima.resources.MessageConstant;
import com.itheima.resources.entity.Result;
import com.itheima.resources.poi.POIUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("ordersetting")
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    @RequestMapping("importOrderSettings.do")
    public Result importOrderSettings(@RequestParam("excelFile") MultipartFile file) {
        try {
            List<String[]> list = POIUtils.readExcel(file);
            // string[0]   日期   string[1]    最大预约数
            orderSettingService.batchOrderSetting(list);
            return new Result(true, MessageConstant.IMPORT_ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.IMPORT_ORDERSETTING_FAIL);
        }

    }


    @RequestMapping("updateOrderSettingData.do")
    public Result updateOrderSettingData(@RequestParam("dateparam") String dateparam, @RequestParam("num") Integer num) {
        try {
            orderSettingService.updateOrderSettingData(dateparam, num);
            return new Result(true, MessageConstant.EDIT_ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_ORDERSETTING_FAIL);
        }

    }

    /**
     * 根据年和月 查询预约数据表    具体月份 对应  最大预约数据 和已经预约数据 +  几号  List<Map>
     *
     * @param
     * @return
     */
    @RequestMapping("findOrderSettingsData.do")
    public Result findOrderSettingsData(@RequestParam("yearAndMonth") String yearAndMonth) {
        try {

            List<Map> map = orderSettingService.findOrderSettingsData(yearAndMonth);

            return new Result(true, MessageConstant.QUERY_ORDERSETTING_SUCCESS, map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_ORDERSETTING_FAIL);
        }

    }


}
